﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;
using Kooboo.HtmlFunc;
using Kooboo.HtmlFunc.Providers;

namespace Kooboo.CMS.SiteConverter.Parser.NVelocity
{
    public class LayoutParser : ParserBase, IParser<ILayout>
    {
        #region IParser<ILayout> Members

        public void Parse(ILayout obj)
        {
            // head
            var markup = new StringBuilder();
            markup.AppendLine("    $Html.FrontHtml().Title()");
            markup.AppendLine("    $Html.FrontHtml().Meta()");
            markup.AppendLine("    $Html.FrontHtml().RegisterStyles()");
            var markupNode = NodeExtension.CreateNode(markup.ToString());
            Razor.LayoutParser.AppendHead(obj.Document, markupNode);

            // script
            var scriptNode = NodeExtension.CreateNode("    $Html.FrontHtml().RegisterScripts()" + Environment.NewLine);
            Razor.LayoutParser.AppendToBody(obj.Document, scriptNode);

            // result
            Razor.LayoutParser.FillResult(obj, this.Context.Result, this.EngineName);
        }

        #endregion
    }
}
